﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Xml.Linq;
using Common.Logging;
using In.Api.Dto.HisWs;
using Newtonsoft.Json;
using OutDbContext;
using Senparc.Weixin.MP.AppStore;
using Senparc.Weixin.MP.Entities;
using Senparc.Weixin.MP.Entities.Request;
using Senparc.Weixin.MP.MessageHandlers;
using User.Api.Helpers;
using User.Api.Helpers.TenPayV2.WxPay;
using User.Api.HttpClients;

namespace User.Api.Models
{
    public class WxCustomMessageHandler : MessageHandler<WxCustomMessageContext>
    {
        private static readonly ILog Logger = LogManager.GetLogger(typeof(WxCustomMessageHandler));

        private static readonly string BaseAddress = ConfigurationManager.AppSettings["BaseAddress"];

        public WxCustomMessageHandler(Stream inputStream, PostModel postModel = null, int maxRecordCount = 0, DeveloperInfo developerInfo = null) 
            : base(inputStream, postModel, maxRecordCount, developerInfo)
        {
        }

        public WxCustomMessageHandler(XDocument requestDocument, PostModel postModel = null, int maxRecordCount = 0, DeveloperInfo developerInfo = null) 
            : base(requestDocument, postModel, maxRecordCount, developerInfo)
        {
        }

        public WxCustomMessageHandler(RequestMessageBase requestMessageBase, PostModel postModel = null, int maxRecordCount = 0, DeveloperInfo developerInfo = null) 
            : base(requestMessageBase, postModel, maxRecordCount, developerInfo)
        {
        }

        public override void OnExecuted()
        {
            base.OnExecuted();
        }

        public override IResponseMessageBase DefaultResponseMessage(IRequestMessageBase requestMessage)
        {
            /* 
             * 所有没有被处理的消息会默认返回这里的结果
            */
            
            var responseMessage = this.CreateResponseMessage<ResponseMessageText>();
            responseMessage.Content = "";
            return responseMessage;
        }

        /// <summary>
        /// 处理文字请求
        /// </summary>
        /// <returns></returns>
        public override IResponseMessageBase OnTextRequest(RequestMessageText requestMessage)
        {
           
            if (requestMessage.Content == "newwx")
            {
                return GetNewWeixin(requestMessage.FromUserName);
            }
            //var responseMessage = ResponseMessageBase.CreateFromRequestMessage<ResponseMessageText>(requestMessage);
            //responseMessage.Content = "";// GetWelcomeInfo();
            //return responseMessage;

            //using (var ctx = new HzfyWeiXinEntities())
            //{
            //   var list= ctx.KeywordReplies.Where(x => requestMessage.Content.Contains(x.Keyword));
            //   if (list.Any())
            //   {
            //       KeywordReply dbkeywordreply = list.OrderByDescending(x => x.Keyword.Length).First();


            //       var responseMessage = CreateResponseMessage<ResponseMessageText>();

            //       responseMessage.Content = dbkeywordreply.ReplyDesc.Trim();

            //       return responseMessage;
            //   }
            //}
            //将微信用户发来的消息转到多客服系统，由客服来处理。
            var responseMessage2 = ResponseMessageBase.CreateFromRequestMessage<ResponseMessageTransfer_Customer_Service>(requestMessage);
            return responseMessage2;
        }



        /// <summary>
        /// 处理位置请求
        /// </summary>
        /// <param name="requestMessage"></param>
        /// <returns></returns>
        public override IResponseMessageBase OnLocationRequest(RequestMessageLocation requestMessage)
        {
            //将微信用户发来的消息转到多客服系统，由客服来处理。
            var responseMessage = ResponseMessageBase.CreateFromRequestMessage<ResponseMessageTransfer_Customer_Service>(requestMessage);
            return responseMessage;
        }

        /// <summary>
        /// 处理图片请求
        /// </summary>
        /// <param name="requestMessage"></param>
        /// <returns></returns>
        public override IResponseMessageBase OnImageRequest(RequestMessageImage requestMessage)
        {
            //将微信用户发来的消息转到多客服系统，由客服来处理。
            var responseMessage = ResponseMessageBase.CreateFromRequestMessage<ResponseMessageTransfer_Customer_Service>(requestMessage);
            return responseMessage;
        }

        /// <summary>
        /// 处理语音请求
        /// </summary>
        /// <param name="requestMessage"></param>
        /// <returns></returns>
        public override IResponseMessageBase OnVoiceRequest(RequestMessageVoice requestMessage)
        {
            //将微信用户发来的消息转到多客服系统，由客服来处理。
            //var responseMessage = ResponseMessageBase.CreateFromRequestMessage<ResponseMessageTransfer_Customer_Service>(requestMessage);
            //var responseMessage = ResponseMessageBase.CreateFromRequestMessage<ResponseMessageText>(requestMessage);
            var responseMessage = ProcessMessage(requestMessage);
            return responseMessage;
        }

        private ResponseMessageText ProcessMessage(RequestMessageVoice message)
        {
            var recognition = message.Recognition;
            if (recognition.Contains("预约"))
            {
                return GetWxAppt(message.FromUserName);
            }
            else if (recognition.Contains("挂号单"))
            {
                return GetReport(message.FromUserName);
            }
            else if (recognition.Contains("挂号"))
            {
                return GetWxAppt(message.FromUserName);
            }
            else if (recognition.Contains("取号"))
            {
                return GetOtherAppt(message.FromUserName);
            }
            else if (recognition.Contains("号"))
            {
                return GetOtherAppt(message.FromUserName);
            }
            else if (recognition.Contains("候诊") || recognition.Contains("队列") || recognition.Contains("排队"))
            {
                return GetQueue(message.FromUserName);
            }
            else if (recognition.Contains("检验"))
            {
                return GetHealthReport(message.FromUserName);
            }
            else if (recognition.Contains("检查"))
            {
                return GetHealthReport(message.FromUserName);
            }
            else if (recognition.Contains("报告"))
            {
                return GetHealthReport(message.FromUserName);
            }
            else if (recognition.Contains("缴费") || recognition.Contains("交费") || recognition.Contains("费"))
            {
                return GetBill(message.FromUserName);
            }
            else if (recognition.Contains("就诊卡") || recognition.Contains("卡"))
            {
                return GetCard(message.FromUserName);
            }
            else if (recognition.Contains("满意"))
            {
                return GetServiceSiPaper(message.FromUserName);
            }
           
            else
            {
                var responseMessage = CreateResponseMessage<ResponseMessageText>();
                var result = new StringBuilder();

                var description = @"";
                result.Append(description).Append("很抱歉！我理解不了你的话语");
                responseMessage.Content = result.ToString();

                return responseMessage;
            }
        }

        /// <summary>
        /// 处理视频请求
        /// </summary>
        /// <param name="requestMessage"></param>
        /// <returns></returns>
        public override IResponseMessageBase OnVideoRequest(RequestMessageVideo requestMessage)
        {
            //将微信用户发来的消息转到多客服系统，由客服来处理。
            var responseMessage = ResponseMessageBase.CreateFromRequestMessage<ResponseMessageTransfer_Customer_Service>(requestMessage);
            return responseMessage;
        }

        /// <summary>
        /// 处理链接消息请求
        /// </summary>
        /// <param name="requestMessage"></param>
        /// <returns></returns>
        public override IResponseMessageBase OnLinkRequest(RequestMessageLink requestMessage)
        {
            //将微信用户发来的消息转到多客服系统，由客服来处理。
            var responseMessage = ResponseMessageBase.CreateFromRequestMessage<ResponseMessageTransfer_Customer_Service>(requestMessage);
            return responseMessage;
        }

        /// <summary>
        /// 处理事件请求（这个方法一般不用重写，这里仅作为示例出现。除非需要在判断具体Event类型以外对Event信息进行统一操作
        /// </summary>
        /// <param name="requestMessage"></param>
        /// <returns></returns>
        public override IResponseMessageBase OnEventRequest(IRequestMessageEventBase requestMessage)
        {
            var eventResponseMessage = base.OnEventRequest(requestMessage);//对于Event下属分类的重写方法，见：CustomerMessageHandler_Events.cs
            //TODO: 对Event信息进行统一操作
            return eventResponseMessage;
        }


        ///// <summary>
        ///// 订阅（关注）事件
        ///// </summary>
        //public override IResponseMessageBase OnEvent_SubscribeRequest(RequestMessageEvent_Subscribe requestMessage)
        //{
        //    var responseMessage = ResponseMessageBase.CreateFromRequestMessage<ResponseMessageText>(requestMessage);
        //    responseMessage.Content = "感谢关注";

        //    return responseMessage;
        //}

        //public override IResponseMessageBase OnTextRequest(RequestMessageText requestMessage)
        //{
        //    var responseMessage = base.CreateResponseMessage<ResponseMessageText>();
        //    responseMessage.Content = "你好";
        //    return responseMessage;
        //}


        private string GetWelcomeInfo()
        {
            //var homeUrl = @"https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx98fca627995d473f&redirect_uri=http%3A%2F%2Fwx.e3861.com%2Fgbkwx%2Fapi%2FAuth%2FWxOauth2%3Furl%3Dhttp%253a%252f%252fwx.e3861.com%252fgbkwx%252fh5%252findex.html&response_type=code&scope=snsapi_userinfo&state=GbkYin666#wechat_redirect";
            var homeUrl = MessageHelper.GetH5Url("");
            var info = $"欢迎关注海珠妇幼保健院官方微信。请使用下方菜单来操作您需要的服务。也可以直接进入我们的<a href=\"{homeUrl}\">微网站</a>，来使用我们的服务哦！";

            return info;
        }

        public override IResponseMessageBase OnTextOrEventRequest(RequestMessageText requestMessage)
        {
            // 预处理文字或事件类型请求。
            // 这个请求是一个比较特殊的请求，通常用于统一处理来自文字或菜单按钮的同一个执行逻辑，
            // 会在执行OnTextRequest或OnEventRequest之前触发，具有以下一些特征：
            // 1、如果返回null，则继续执行OnTextRequest或OnEventRequest
            // 2、如果返回不为null，则终止执行OnTextRequest或OnEventRequest，返回最终ResponseMessage
            // 3、如果是事件，则会将RequestMessageEvent自动转为RequestMessageText类型，其中RequestMessageText.Content就是RequestMessageEvent.EventKey

            return null;//返回null，则继续执行OnTextRequest或OnEventRequest
        }

        public override IResponseMessageBase OnEvent_ClickRequest(RequestMessageEvent_Click requestMessage)
        {
            //微信用户openid
            var wxOpenId = requestMessage.FromUserName;

            IResponseMessageBase reponseMessage = null;
            //菜单点击，需要跟创建菜单时的Key匹配
            switch (requestMessage.EventKey)
            {
                case "hospital_info"://医院信息
                    reponseMessage = GetHospitalInfo(wxOpenId);
                    break;
                case "department_info"://科室信息
                    reponseMessage = GetDepartmentInfo(wxOpenId);
                    break;
                case "doctor_info"://医生信息
                    reponseMessage = GetDoctorInfo(wxOpenId);
                    break;
                //case "notice_info"://医院公告
                //    reponseMessage = GetHospNoticeInfo(wxOpenId);
                //    break;
                case "service_guahao"://挂号
                    reponseMessage = GetWxAppt(wxOpenId);
                    break;
                //case "service_quhao"://取号
                //    reponseMessage = GetOtherAppt(wxOpenId);
                //    break;
                case "service_hezhenduilie"://候诊队列
                    reponseMessage = GetQueue(wxOpenId);
                    break;
                case "pay_service"://就诊缴费
                    reponseMessage = GetBill(wxOpenId);
                    break;
                case "report_service"://取报告单
                    reponseMessage = GetHealthReport(wxOpenId);
                    break;
                case "my_bill"://我的单据
                    reponseMessage = GetReport(wxOpenId);
                    break;
                case "my_card"://我的就诊卡
                    reponseMessage = GetCard(wxOpenId);
                    break;
                case "service_explain"://服务说明
                    reponseMessage = GetServiceDescription(wxOpenId);
                    break;
                case "sipaper_service"://满意度调查
                    reponseMessage = GetServiceSiPaper(wxOpenId);
                    break;
                //case "service_inpatienthistory"://住院历史
                //    reponseMessage = GetInpatientHistory(wxOpenId);
                //    break;
                //case "service_dinner": //订餐服务
                //    reponseMessage = GetDinnerInfo(wxOpenId);
                //    break;
                default:
                    {
                        var strongResponseMessage = CreateResponseMessage<ResponseMessageText>();
                        reponseMessage = strongResponseMessage;
                        strongResponseMessage.Content = "功能开发中，敬请期待！";
                    }
                    break;
            }

            return reponseMessage;
        }

        public override IResponseMessageBase OnEvent_EnterRequest(RequestMessageEvent_Enter requestMessage)
        {
            var responseMessage = ResponseMessageBase.CreateFromRequestMessage<ResponseMessageText>(requestMessage);
            responseMessage.Content = "";
            return responseMessage;
        }

        public override IResponseMessageBase OnEvent_LocationRequest(RequestMessageEvent_Location requestMessage)
        {
            var responseMessage = ResponseMessageBase.CreateFromRequestMessage<ResponseMessageText>(requestMessage);
            responseMessage.Content = "";
            return responseMessage;
        }

        public override IResponseMessageBase OnEvent_ViewRequest(RequestMessageEvent_View requestMessage)
        {
            //说明：这条消息只作为接收，下面的responseMessage到达不了客户端，类似OnEvent_UnsubscribeRequest
            var responseMessage = CreateResponseMessage<ResponseMessageText>();
            responseMessage.Content = "您点击了view按钮，将打开网页：" + requestMessage.EventKey;
            return responseMessage;
        }


        /// <summary>
        /// 扫描二维码绑卡，用户已关注微信时，调用此方法
        /// </summary>
        /// <param name="requestMessage"></param>
        /// <returns></returns>
        public override IResponseMessageBase OnEvent_ScanRequest(RequestMessageEvent_Scan requestMessage)
        {
            var responseMessageContent = "";
            var eventKey = requestMessage.EventKey.Replace("qrscene_", "");
            var openId = requestMessage.FromUserName;
            var sceneId = Int32.Parse(eventKey);
            //HospCard card = null;
            //var resultCode = CardService.BindCardByScan(sceneId, openId, out card);
            //if (resultCode == 1)//超出最大绑卡数量
            //{
            //    responseMessageContent = "绑卡失败，原因：超出最大绑卡数量。\r\n如需帮助，请与客服联系。";
            //}
            //else if (resultCode == 2)
            //{
            //    responseMessageContent = "您已经添加过此就诊卡，请不要重复添加。\r\n如需帮助，请与客服联系。";
            //}
            //else if (resultCode == 0) //绑卡成功
            //{
            //    if (card != null)
            //    {
            //        var patientName = card.PatientName;
            //        var cardType = card.CardType == 0
            //            ? "诊疗卡"
            //            : card.CardType == 1 ? "健康卡" : card.CardType == 2 ? "市民卡" : "";
            //        var cardNo = card.CardNo;
            //        var sb = new StringBuilder();
            //        sb.Append("扫描二维码绑卡成功。您的就诊卡信息如下：\r\n");
            //        sb.AppendFormat("姓名：{0}", patientName).Append("\r\n");
            //        sb.AppendFormat("卡号：{0}", cardNo).Append("\r\n");
            //        sb.AppendFormat("卡类型：{0}", cardType).Append("\r\n");
            //        responseMessageContent = sb.ToString();
            //    }
            //}

            var responseMessage = ResponseMessageBase.CreateFromRequestMessage<ResponseMessageText>(requestMessage);
            responseMessage.Content = responseMessageContent;
            return responseMessage;


            //通过扫描关注
            //return base.OnEvent_ScanRequest(requestMessage);
        }


        /// <summary>
        /// 订阅（关注）事件。通过“EventKey”来区分用户是否是从带场景值的二维码来关注，如是，自动给用户绑定卡信息
        /// </summary>
        /// <returns></returns>
        public override IResponseMessageBase OnEvent_SubscribeRequest(RequestMessageEvent_Subscribe requestMessage)
        {
            var now = DateTime.Now;
            using (var ctx = new HzfyWeiXinEntities())
            {
                var user = ctx.WxUser.FirstOrDefault(p => p.OpenId == requestMessage.FromUserName);
                if (user != null)
                {
                    user.SubscribeDt = now;
                    user.UnsubscribeDt = null;
                    user.LastActiveDt = now;
                    user.RecStatus = 1;
                    ctx.SaveChanges();
                }
                else
                {
                    user = new OutDbContext.WxUser
                    {
                        OpenId = requestMessage.FromUserName,
                        SubscribeDt = now,
                        LastActiveDt = now,
                        IsBkMember = 0,
                        RecStatus = 1,
                        RecCreateDt = now
                    };
                    ctx.WxUser.Add(user);
                    ctx.SaveChanges();
                }
            }

            var responseMessageContent = "";
            var eventKey = requestMessage.EventKey.Replace("qrscene_", "");
            if (string.IsNullOrEmpty(eventKey))
            {
                responseMessageContent = GetWelcomeInfo();
            }
            else
            {
                responseMessageContent = GetWelcomeInfo();

                //var openId = requestMessage.FromUserName;
                //var sceneId = Int64.Parse(eventKey.Replace("qrscene_", ""));
                //HospCard card = null;
                //var resultCode = CardService.BindCardByScan(sceneId, openId, out card);
                //if (resultCode == 1)//超出最大绑卡数量
                //{
                //    responseMessageContent += "\r\n\r\n" + "扫描二维码绑卡失败，原因：超出最大绑卡数量。\r\n如需帮助，请与客服联系。";
                //}
                //else if (resultCode == 2)
                //{
                //    responseMessageContent += "\r\n\r\n" + "您已经添加过此就诊卡，请不要重复添加。\r\n如需帮助，请与客服联系。";
                //}
                //else if (resultCode == 0)//绑卡成功
                //{
                //    if (card != null)
                //    {
                //        var patientName = card.PatientName;
                //        var cardType = card.CardType == 0 ? "诊疗卡" : card.CardType == 1 ? "健康卡" : card.CardType == 2 ? "市民卡" : "";
                //        var cardNo = card.CardNo;
                //        var sb = new StringBuilder();
                //        sb.Append("扫描二维码绑卡成功。您的就诊卡信息如下：\r\n");
                //        sb.AppendFormat("姓名：{0}", patientName).Append("\r\n");
                //        sb.AppendFormat("卡号：{0}", cardNo).Append("\r\n");
                //        sb.AppendFormat("卡类型：{0}", cardType).Append("\r\n");

                //        responseMessageContent += "\r\n\r\n" + sb.ToString();
                //    }
                //}
            }

            var responseMessage = ResponseMessageBase.CreateFromRequestMessage<ResponseMessageText>(requestMessage);
            responseMessage.Content = responseMessageContent;
            return responseMessage;

        }



        /// <summary>
        /// 退订
        /// 实际上用户无法收到非订阅账号的消息，所以这里可以随便写。
        /// unsubscribe事件的意义在于及时删除网站应用中已经记录的OpenID绑定，消除冗余数据。并且关注用户流失的情况。
        /// </summary>
        /// <returns></returns>
        public override IResponseMessageBase OnEvent_UnsubscribeRequest(RequestMessageEvent_Unsubscribe requestMessage)
        {
            using (var ctx = new HzfyWeiXinEntities())
            {
                var user = ctx.WxUser.FirstOrDefault(p => p.OpenId == requestMessage.FromUserName);
                if (user != null)
                {
                    var now = DateTime.Now;
                    user.UnsubscribeDt = now;
                    user.LastActiveDt = now;
                    ctx.SaveChanges();
                }
            }

            var responseMessage = base.CreateResponseMessage<ResponseMessageText>();
            responseMessage.Content = "";
            return responseMessage;
        }


        public ResponseMessageNews GetHospitalInfo(string wxOpenId)
        {
            var strongResponseMessage = CreateResponseMessage<ResponseMessageNews>();
            strongResponseMessage.Articles.Add(new Article()
            {
                Title = "医院介绍",
                Description = "        广州市海珠妇幼保健院..",
                PicUrl = BaseAddress + "/Images/hzffyHosp.jpg",
                Url = MessageHelper.GetH5Url("/index/hosp-desc")
            });
            strongResponseMessage.Articles.Add(new Article()
            {
                Title = "科室介绍",
                Description = "",
                PicUrl = "",
                Url = MessageHelper.GetH5Url("/index/depart-list?branchName=panyu&purpose=detail")
            });
            return strongResponseMessage;
        }

        public ResponseMessageNews GetDepartmentInfo(string wxOpenId)
        {
            var strongResponseMessage = CreateResponseMessage<ResponseMessageNews>();
            strongResponseMessage.Articles.Add(new Article()
            {
                Title = "科室介绍",
                Description = "        广州市海珠妇幼保健院，引进了国内外先进的医疗设备，多个科室被评为省市重点示范单位...",
                PicUrl = BaseAddress + "/Images/departIntroduce.jpg",
                Url = MessageHelper.GetH5Url("/index/depart-list?branchName=panyu&purpose=detail")
            });

            return strongResponseMessage;
        }

        public ResponseMessageNews GetDoctorInfo(string wxOpenId)
        {

            var strongResponseMessage = CreateResponseMessage<ResponseMessageNews>();
            strongResponseMessage.Articles.Add(new Article()
            {
                Title = "医生介绍",
                Description = "        广州市海珠妇幼保健院，拥有一支临床经验丰富而积极于学术研究的医生团队...",
                PicUrl = BaseAddress + "/Images/doctorIntroduce.jpg",
                Url = ""
            });

            return strongResponseMessage;
        }



        /// <summary>
        /// 在线挂号
        /// </summary>
        /// <returns></returns>
        public ResponseMessageText GetWxAppt(string wxOpenId)
        {
            var responseMessage = CreateResponseMessage<ResponseMessageText>();
            var result = new StringBuilder();

            var description = @"在线挂号说明 ";

            var guaHaoUrl = MessageHelper.GetH5Url("/index/depart-list?branchName=panyu&purpose=appt");
 
            result.Append(description).Append("\r\n\r\n");
            result.AppendFormat("<a href=\"{0}\">点这里【在线挂号】</a>", guaHaoUrl).Append("\r\n");

            responseMessage.Content = result.ToString();

            return responseMessage;
        }



        /// <summary>
        /// 在线取号
        /// </summary>
        /// <returns></returns>
        public ResponseMessageText GetOtherAppt(string wxOpenId)
        {
            var responseMessage = CreateResponseMessage<ResponseMessageText>();
//            var result = new StringBuilder();

//            var description = @"在线取号说明
//1.在其他平台（官网、电话）预约，使用本院诊疗卡预约的取号以及医生诊间加号的取号。
//2.如因您自身原因迟到，系统将自动安排您在本班次最后就诊或者退号重新现场挂号。";
//            //4.如需退预约号，请于支付当天晚12点前办理，超时请在就诊日期前移步就诊院区的人工窗口办理。";

//            var url = MessageHelper.GetH5Url("/index/get-other-appt");

//            result.Append(description).Append("\r\n\r\n"); ;
//            result.AppendFormat("<a href=\"{0}\">点这里【在线取号】</a>", url);
//            responseMessage.Content = result.ToString();

            return responseMessage;
        }


        /// <summary>
        /// 候诊队列
        /// </summary>
        /// <returns></returns>
        public ResponseMessageText GetQueue(string wxOpenId)
        {
            var responseMessage = CreateResponseMessage<ResponseMessageText>();
            var result = new StringBuilder();

            var description = @"候诊队列说明
1.候诊队列支持实时查询候诊信息，可能因网络延时等原因造成信息不一致，微信查询仅供参考，请以现场候诊队列信息为准。";

            var url = MessageHelper.GetH5Url("/index/get-queue");

            result.Append(description).Append("\r\n\r\n");
            result.AppendFormat("<a href=\"{0}\">点这里查看【候诊队列】</a>", url).Append("\r\n");

            responseMessage.Content = result.ToString();

            return responseMessage;
        }



        /// <summary>
        /// 就诊缴费
        /// </summary>
        /// <returns></returns>
        public ResponseMessageText GetBill(string wxOpenId)
        {
            var responseMessage = CreateResponseMessage<ResponseMessageText>();
            var result = new StringBuilder();

            var description = @"就诊缴费说明
                        1.缴费提供微信支付\n
                        2.处方单三天内缴费有效
                        3.目前微信支付只提供自费缴费，如需医保、公费记账请移步到各楼层人工缴费窗口缴费
                        4.如需打印发票或办理退费请凭微信缴费“电子凭条”到人工收费窗口打印
                        5.如需打印费用清单请“电子凭条”到前台服务窗口打印";

            var url = MessageHelper.GetH5Url("/index/get-bill");

            result.Append(description).Append("\r\n\r\n"); ;
            result.AppendFormat("<a href=\"{0}\">点这里【就诊缴费】</a>", url).Append("\r\n"); ;

            responseMessage.Content = result.ToString();

            return responseMessage;
        }


        /// <summary>
        /// 取报告单
        /// </summary>
        /// <returns></returns>
        public ResponseMessageText GetHealthReport(string wxOpenId)
        {
            var responseMessage = CreateResponseMessage<ResponseMessageText>();
            var result = new StringBuilder();

            var description = @"报告单说明 ";

            
            var inspectionUrl = MessageHelper.GetH5Url("/index/get-inspection");

            result.Append(description).Append("\r\n\r\n");
        
            result.AppendFormat("<a href=\"{0}\">点这里【取检验单】</a>", inspectionUrl).Append("\r\n");

            responseMessage.Content = result.ToString();

            return responseMessage;
        }



        /// <summary>
        /// 我的单据
        /// </summary>
        /// <returns></returns>
        public ResponseMessageText GetReport(string wxOpenId)
        {
            //微信openid验证签名，防止用户在url中伪造openid来访问
            var wxSign = MD5SignUtil.Sign(wxOpenId, "gdsfybjy");

            var responseMessage = CreateResponseMessage<ResponseMessageText>();
            var result = new StringBuilder();

            var description = @"单据管理说明 
                         1.可以查询本微信号挂号与缴费订单。";

            var apptRegOrderUrl = MessageHelper.GetH5Url("/index/reg-order-list");
            var paidBillUrl = MessageHelper.GetH5Url("/index/bill-order-list");
 

            result.Append(description).Append("\r\n\r\n");
            result.AppendFormat("<a href=\"{0}\">点这里【查询挂号单】</a>", apptRegOrderUrl).Append("\r\n\r\n");
            result.AppendFormat("<a href=\"{0}\">点这里【查询缴费单】</a>", paidBillUrl).Append("\r\n\r\n");
 

            responseMessage.Content = result.ToString();
            return responseMessage;
        }



        /// <summary>
        /// 我的就诊卡
        /// </summary>
        /// <returns></returns>
        public ResponseMessageText GetCard(string wxOpenId)
        {
            var responseMessage = CreateResponseMessage<ResponseMessageText>();
            var result = new StringBuilder();

            var description = @"就诊卡管理说明
1.绑定就诊卡，允许绑定多张就诊卡。";

            var url = MessageHelper.GetH5Url("/index/manage-card");

            result.Append(description).Append("\r\n\r\n");
            result.AppendFormat("<a href=\"{0}\">点这里【管理就诊卡】</a>", url).Append("\r\n"); ;

            responseMessage.Content = result.ToString();

            return responseMessage;
        }


        /// <summary>
        /// 服务说明
        /// </summary>
        /// <returns></returns>
        public ResponseMessageText GetServiceDescription(string wxOpenId)
        {
            var responseMessage = CreateResponseMessage<ResponseMessageText>();
            var result = new StringBuilder();

            var description = @"";

            var url = MessageHelper.GetH5Url("/index/hosp-service-desc");

            result.Append(description).Append("");
            result.AppendFormat("<a href=\"{0}\">点这里查看【服务说明】</a>", url).Append("\r\n"); ;

            responseMessage.Content = result.ToString();

            return responseMessage;
        }

        /// <summary>
        /// 满意度调查
        /// </summary>
        /// <returns></returns>
        public ResponseMessageText GetServiceSiPaper(string wxOpenId)
        {
            var responseMessage = CreateResponseMessage<ResponseMessageText>();
            var result = new StringBuilder();

            var description = @"";

            var url = MessageHelper.GetH5Url("/index/paper-list");

            result.Append(description).Append("");
            result.AppendFormat("<a href=\"{0}\">点这里【满意度调查】</a>", url).Append("\r\n"); ;

            responseMessage.Content = result.ToString();

            return responseMessage;
        }







        /// <summary>
        /// 测试
        /// </summary>
        /// <param name="wxOpenId"></param>
        /// <returns></returns>
        public ResponseMessageText GetNewWeixin(string wxOpenId)
        {
            var responseMessage = CreateResponseMessage<ResponseMessageText>();
            var result = new StringBuilder();
            var url = @"https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx98fca627995d473f&redirect_uri=http%3A%2F%2Fwx.e3861.com%2Fapi%2FAuth%2FWxOauth2%3Furl%3Dhttp%253a%252f%252fwx.e3861.com%252fh5%252findex.html%2523%21&response_type=code&scope=snsapi_userinfo&state=GbkYin666#wechat_redirect";

            result.AppendFormat("<a href=\"{0}\">点这里【XINWEIXIN】</a>", url).Append("\r\n\r\n");

            responseMessage.Content = result.ToString();

            return responseMessage;
        }

    }



}